package org.sn.jdish.example.queue;

/**
 * 队列FIFO
 * 
 * @author snzigod@hotmail.com
 *
 */
public class Queue {

	public Node head;
	public Node cur;

	public int size = 0;

	public void enQueue(Object data) {
		if (head == null) {
			head = new Node(data);
			cur = head;
		} else {
			cur.next = new Node(data);
			cur = cur.next;
		}
		size++;
	}

	public Object deQueue() {
		if (head == null) {
			return null;
		}
		Node node = head;
		head = head.next;
		size--;
		return node.data;
	}

	public boolean empty() {
		return size == 0;
	}

	class Node {
		Object data;
		Node next;

		public Node(Object data) {
			this.data = data;
		}
	}

	public static void main(String[] args) {
		Queue queue = new Queue();
		for (int i = 0; i < 5; i++) {
			queue.enQueue(i);
		}
		while (!queue.empty()) {
			System.out.println(queue.deQueue());
		}
	}

}
